using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Microsoft.SqlServer.Dts.Pipeline.Wrapper;

namespace BILab.Technical.BI.ETL.Pipeline.XmlDestination
{
	public partial class XmlDestinationAdapterUIForm: Form
	{
		private const string Const_FileName_AttributeName = "Filename";
		private const string Const_XmlRootTag_AttributeName = "Xml Root Tag";
		private const string Const_XmlRowTag_AttributeName = "Xml Row Tag";
		private const string Const_XmlNbOfRowsTag_AttributeName = "Xml Number of Rows Tag";
		private const string Const_OutputNbOfRows_AttributeName = "Output Number Of Rows";


		IDTSComponentMetaData90 _md;

		public XmlDestinationAdapterUIForm(IDTSComponentMetaData90 dtsComponentMetadata)
		{
			InitializeComponent();
			this._md = dtsComponentMetadata;
			displayProperties();
		}

		private void PbOk_Click(object sender, EventArgs e)
		{
			this._md.CustomPropertyCollection[Const_FileName_AttributeName].Value =this.Tbfilename.Text;
			this._md.CustomPropertyCollection[Const_XmlRootTag_AttributeName].Value =this.TbXmlRootTag.Text;
			this._md.CustomPropertyCollection[Const_XmlRowTag_AttributeName].Value =this.TbXmlRowTag.Text;
			this._md.CustomPropertyCollection[Const_XmlNbOfRowsTag_AttributeName].Value =this.TbXmlNbRowsTag.Text;
			this._md.CustomPropertyCollection[Const_OutputNbOfRows_AttributeName].Value = this.CheckXmlNbRowsTag.Checked;
			base.DialogResult = DialogResult.OK;
		}

		private void PbCancel_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void displayProperties()
		{
			this.Tbfilename.Text = (string)this._md.CustomPropertyCollection[Const_FileName_AttributeName].Value;
			this.TbXmlRootTag.Text = (string)this._md.CustomPropertyCollection[Const_XmlRootTag_AttributeName].Value;
			this.TbXmlRowTag.Text = (string)this._md.CustomPropertyCollection[Const_XmlRowTag_AttributeName].Value;

			CheckXmlNbRowsTag.Checked = (bool) this._md.CustomPropertyCollection[Const_OutputNbOfRows_AttributeName].Value;

			if (CheckXmlNbRowsTag.Checked)
			{
				TbXmlNbRowsTag.Enabled = true;
			}
			else
			{
				TbXmlNbRowsTag.Enabled = false;
			}


			this.TbXmlNbRowsTag.Text = (string)this._md.CustomPropertyCollection[Const_XmlNbOfRowsTag_AttributeName].Value;

		}

		private void CheckXmlNbRowsTag_CheckedChanged(object sender, EventArgs e)
		{
			if (CheckXmlNbRowsTag.Checked)
			{
				TbXmlNbRowsTag.Enabled = true;
			}
			else
			{
				TbXmlNbRowsTag.Enabled = false;
			}

		}

		private void PbOpenDialog_Click(object sender, EventArgs e)
		{
			saveFileDialog1.FileName = this.Tbfilename.Text;
			DialogResult result = saveFileDialog1.ShowDialog();

			if (result == DialogResult.OK)
			{
				this.Tbfilename.Text = saveFileDialog1.FileName;
			}
		}
	}
}